Using vendor prefix common infrastructure
diff --git a/vibration/api-is-present.html b/vibration/api-is-present.html index 4a53ad6..be802c2 100644 --- a/vibration/api-is-present.html +++ b/vibration/api-is-present.html
@@ -5,12 +5,8 @@ <title>Vibration API: test that the vibrate() method is present (with or without vendor prefix)</title> <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/> <link rel='help' href='http://www.w3.org/TR/vibration/#methods'/> - <meta name='flags' content='vendor-prefix, dom'/> + <meta name='flags' content='dom'/> <meta name='assert' content='Check that the vibrate() method is present.'/> - <!-- - When you review this test, please add - <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/> - --> <link rel='stylesheet' href='/resources/testharness.css' media='all'/> </head> <body> @@ -21,11 +17,11 @@ </p> <div id='log'></div> <script src='/resources/testharness.js'></script> - <!-- When this test gets approved, remove a "../" below --> - <script src='support/feature-detection.js'></script> + <script src='/resources/testharnessreport.js'></script> + <script src='/common/vendor-prefix.js' data-prefixed-objects='[{"ancestors":["navigator"], "name":"vibrate"}]'></script> <script> test(function () { - assert_true(undefined !== BrowserHasFeature(navigator, "vibrate"), "navigator.vibrate exists"); + assert_true(undefined !== navigator.vibrate, "navigator.vibrate exists"); }, "vibrate() is present on navigator"); </script> </body> diff --git a/vibration/cancel-with-0.html b/vibration/cancel-with-0.html index 15cd184..7b9ceaa 100644 --- a/vibration/cancel-with-0.html +++ b/vibration/cancel-with-0.html
@@ -5,9 +5,9 @@ <title>Vibration API: cancel ongoing vibrate() with 0</title> <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/> <link rel='help' href='http://www.w3.org/TR/vibration/#methods'/> - <meta name='flags' content='vendor-prefix, dom, interact'/> + <meta name='flags' content='dom, interact'/> <meta name='assert' content='If pattern is 0, cancel the pre-existing instance of the processing vibration patterns algorithm'/> - <!-- + <!-- When you review this test, please add <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/> --> @@ -23,11 +23,10 @@ <button id='vib'>Vibrate!</button> <div id='log'></div> <script src='/resources/testharness.js'></script> - <!-- When this test gets approved, remove a "../" below --> - <script src='support/feature-detection.js'></script> - <script src='support/helpers.js'></script> + <script src='/resources/testharnessreport.js'></script> + <script src='/common/vendor-prefix.js' data-prefixed-objects='[{"ancestors":["navigator"], "name":"vibrate"}]'></script> <script> - if (supportsVibration()) { + if (undefined !== navigator.vibrate) { document.getElementById("vib").onclick = function () { navigator.vibrate(5000); setTimeout(function () { diff --git "a/vibration/cancel-with-\133\135-manual.html" "b/vibration/cancel-with-\133\135-manual.html" index e4d4d1a..1b3106e 100644 --- "a/vibration/cancel-with-\133\135-manual.html" +++ "b/vibration/cancel-with-\133\135-manual.html"
@@ -5,9 +5,9 @@ <title>Vibration API: cancel ongoing vibrate() with []</title> <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/> <link rel='help' href='http://www.w3.org/TR/vibration/#methods'/> - <meta name='flags' content='vendor-prefix, dom, interact'/> + <meta name='flags' content='dom, interact'/> <meta name='assert' content='If pattern is an empty list, cancel the pre-existing instance of the processing vibration patterns algorithm'/> - <!-- + <!-- When you review this test, please add <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/> --> @@ -23,11 +23,10 @@ <button id='vib'>Vibrate!</button> <div id='log'></div> <script src='/resources/testharness.js'></script> - <!-- When this test gets approved, remove a "../" below --> - <script src='support/feature-detection.js'></script> - <script src='support/helpers.js'></script> + <script src='/resources/testharnessreport.js'></script> + <script src='/common/vendor-prefix.js' data-prefixed-objects='[{"ancestors":["navigator"], "name":"vibrate"}]'></script> <script> - if (supportsVibration()) { + if (undefined !== navigator.vibrate) { document.getElementById("vib").onclick = function () { navigator.vibrate(5000); setTimeout(function () { diff --git a/vibration/cancel-with-new.html b/vibration/cancel-with-new.html index 15a9e58..9c8044e 100644 --- a/vibration/cancel-with-new.html +++ b/vibration/cancel-with-new.html
@@ -5,9 +5,9 @@ <title>Vibration API: cancel ongoing vibrate() with a new call to vibrate</title> <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/> <link rel='help' href='http://www.w3.org/TR/vibration/#methods'/> - <meta name='flags' content='vendor-prefix, dom, interact'/> + <meta name='flags' content='dom, interact'/> <meta name='assert' content='Cancel the pre-existing instance of the processing vibration patterns algorithm, if any.'/> - <!-- + <!-- When you review this test, please add <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/> --> @@ -24,11 +24,10 @@ <button id='vib'>Vibrate!</button> <div id='log'></div> <script src='/resources/testharness.js'></script> - <!-- When this test gets approved, remove a "../" below --> - <script src='support/feature-detection.js'></script> - <script src='support/helpers.js'></script> + <script src='/resources/testharnessreport.js'></script> + <script src='/common/vendor-prefix.js' data-prefixed-objects='[{"ancestors":["navigator"], "name":"vibrate"}]'></script> <script> - if (supportsVibration()) { + if (undefined !== navigator.vibrate) { document.getElementById("vib").onclick = function () { navigator.vibrate(5000); setTimeout(function () { diff --git a/vibration/pattern-array-extra.html b/vibration/pattern-array-extra.html index 5d049f3..61dbabd 100644 --- a/vibration/pattern-array-extra.html +++ b/vibration/pattern-array-extra.html
@@ -5,9 +5,9 @@ <title>Vibration API: test a pattern array parameter to vibrate() with an extra (even) item</title> <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/> <link rel='help' href='http://www.w3.org/TR/vibration/#methods'/> - <meta name='flags' content='vendor-prefix, dom, interact'/> + <meta name='flags' content=dom, interact'/> <meta name='assert' content='If the length of pattern is even, then remove the last entry in pattern.'/> - <!-- + <!-- When you review this test, please add <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/> --> @@ -22,11 +22,10 @@ <button id='vib'>Vibrate!</button> <div id='log'></div> <script src='/resources/testharness.js'></script> - <!-- When this test gets approved, remove a "../" below --> - <script src='support/feature-detection.js'></script> - <script src='support/helpers.js'></script> + <script src='/resources/testharnessreport.js'></script> + <script src='/common/vendor-prefix.js' data-prefixed-objects='[{"ancestors":["navigator"], "name":"vibrate"}]'></script> <script> - if (supportsVibration()) { + if (undefined !== navigator.vibrate) { document.getElementById("vib").onclick = function () { navigator.vibrate([1000, 1000, 1000, 1000, 1000, 1000]); }; diff --git a/vibration/pattern-array.html b/vibration/pattern-array.html index 5209ef1..d01b065 100644 --- a/vibration/pattern-array.html +++ b/vibration/pattern-array.html
@@ -5,8 +5,8 @@ <title>Vibration API: test a pattern array parameter to vibrate()</title> <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/> <link rel='help' href='http://www.w3.org/TR/vibration/#methods'/> - <meta name='flags' content='vendor-prefix, dom, interact'/> - <!-- + <meta name='flags' content=dom, interact'/> + <!-- When you review this test, please add <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/> --> @@ -21,11 +21,10 @@ <button id='vib'>Vibrate!</button> <div id='log'></div> <script src='/resources/testharness.js'></script> - <!-- When this test gets approved, remove a "../" below --> - <script src='support/feature-detection.js'></script> - <script src='support/helpers.js'></script> + <script src='/resources/testharnessreport.js'></script> + <script src='/common/vendor-prefix.js' data-prefixed-objects='[{"ancestors":["navigator"], "name":"vibrate"}]'></script> <script> - if (supportsVibration()) { + if (undefined !== navigator.vibrate) { document.getElementById("vib").onclick = function () { navigator.vibrate([1000, 1000, 1000, 1000, 1000]); }; diff --git a/vibration/silent-ignore.html b/vibration/silent-ignore.html index 4a63461..508cafa 100644 --- a/vibration/silent-ignore.html +++ b/vibration/silent-ignore.html
@@ -5,9 +5,9 @@ <title>Vibration API: test that calls to vibrate() are silently ignored when the device cannot vibrate</title> <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/> <link rel='help' href='http://www.w3.org/TR/vibration/#methods'/> - <meta name='flags' content='vendor-prefix, dom, no-vibrator'/> + <meta name='flags' content='dom, no-vibrator'/> <meta name='assert' content='If the device does not provide a vibration mechanism, or it is disabled, the user agent must silently ignore any invocations of the vibrate() method.'/> - <!-- + <!-- When you review this test, please add <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/> --> @@ -23,11 +23,11 @@ </p> <div id='log'></div> <script src='/resources/testharness.js'></script> - <script src='support/feature-detection.js'></script> - <script src='support/helpers.js'></script> + <script src='/resources/testharnessreport.js'></script> + <script src='/common/vendor-prefix.js' data-prefixed-objects='[{"ancestors":["navigator"], "name":"vibrate"}]'></script> <script> - if (supportsVibration()) { - test(function () { + if (undefined !== navigator.vibrate) { + test(function () { assert_true(navigator.vibrate(1000), "vibrate() returns true when vibration is not supported"); }, "Calling vibrate returns true"); } diff --git a/vibration/simple-array-manual.html b/vibration/simple-array-manual.html index 76c1710..6d44104 100644 --- a/vibration/simple-array-manual.html +++ b/vibration/simple-array-manual.html
@@ -5,8 +5,8 @@ <title>Vibration API: test a simple array parameter to vibrate()</title> <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/> <link rel='help' href='http://www.w3.org/TR/vibration/#methods'/> - <meta name='flags' content='vendor-prefix, dom, interact'/> - <!-- + <meta name='flags' content='dom, interact'/> + <!-- When you review this test, please add <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/> --> @@ -20,11 +20,10 @@ <button id='vib'>Vibrate!</button> <div id='log'></div> <script src='/resources/testharness.js'></script> - <!-- When this test gets approved, remove a "../" below --> - <script src='support/feature-detection.js'></script> - <script src='support/helpers.js'></script> + <script src='/resources/testharnessreport.js'></script> + <script src='/common/vendor-prefix.js' data-prefixed-objects='[{"ancestors":["navigator"], "name":"vibrate"}]'></script> <script> - if (supportsVibration()) { + if (undefined !== navigator.vibrate) { var t = async_test("Tests that vibrate returns true", {timeout: 10000}); document.getElementById("vib").onclick = t.step_func(function () { diff --git a/vibration/simple-scalar.html b/vibration/simple-scalar.html index e0dc8a9..ee47daa 100644 --- a/vibration/simple-scalar.html +++ b/vibration/simple-scalar.html
@@ -5,8 +5,8 @@ <title>Vibration API: test a simple scalar parameter to vibrate()</title> <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/> <link rel='help' href='http://www.w3.org/TR/vibration/#methods'/> - <meta name='flags' content='vendor-prefix, dom, interact'/> - <!-- + <meta name='flags' content='dom, interact'/> + <!-- When you review this test, please add <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/> --> @@ -20,11 +20,10 @@ <button id='vib'>Vibrate!</button> <div id='log'></div> <script src='/resources/testharness.js'></script> - <!-- When this test gets approved, remove a "../" below --> - <script src='support/feature-detection.js'></script> - <script src='support/helpers.js'></script> + <script src='/resources/testharnessreport.js'></script> + <script src='/common/vendor-prefix.js' data-prefixed-objects='[{"ancestors":["navigator"], "name":"vibrate"}]'></script> <script> - if (supportsVibration()) { + if (undefined !== navigator.vibrate) { document.getElementById("vib").onclick = function () { navigator.vibrate(2000); }; diff --git a/vibration/support/feature-detection.js b/vibration/support/feature-detection.js deleted file mode 100644 index 6e8c304..0000000 --- a/vibration/support/feature-detection.js +++ /dev/null
@@ -1,94 +0,0 @@ - -// 2012-01-27 -// The code below has been stolen from Microsoft's submission tests to the Page Visibility -// specification. Thanks! - - -// This function returns the value of an API feature if it is defined with one of -// the known ventor prefixes. -// -// Parameters: -// parent: the object containing the API feature -// feature: the name of the API feature, this should be a string value -// isAttribute: set this to true to indicate that this is a constant attribute -// as opposed to a variable -function BrowserHasFeature(parent, feature, isAttribute) -{ - if (parent[feature] !== undefined) - { - //feature is defined without a vendor prefix, no further checks necessary - return parent[feature]; - } - - // the feature is not defined without a vendor prefix, so find the vendor prefix, if any, - // that it is defined with - var prefix = GetVendorPrefix(parent, feature, isAttribute); - - // if prefix is not undefined, then the feature has been found to exist with this prefix - if (prefix !== undefined) - { - var prefixedFeatureName = AppendPrefix(prefix, feature, isAttribute); - return parent[prefixedFeatureName]; - } - - //The feature does not exist. - //Callers should check for !==undefined as the feature itself could return - //a Bool which would fail a typical if(feature) check - return undefined; -} - -// This function returns the vendor prefix found if a certain feature is defined with it. -// It takes the same parameters at BrowserHasFeature(). -function GetVendorPrefix(parent, feature, isAttribute) -{ - //Known vendor prefixes - var VendorPrefixes = ["moz", "ms", "o", "webkit"]; - for (vendor in VendorPrefixes) - { - //Build up the new feature name with the vendor prefix - var prefixedFeatureName = AppendPrefix(VendorPrefixes[vendor], feature, isAttribute); - if (parent[prefixedFeatureName] !== undefined) - { - //Vendor prefix version exists, return a pointer to the feature - return VendorPrefixes[vendor]; - } - } - - // if no version of the feature with a vendor prefix has been found, return undefined - return undefined; -} - -// This will properly capitalize the feature name and then return the feature name preceded -// with the provided vendor prefix. If the prefix given is undefined, this function will -// return the feature name given as is. The output of this function should not be used -// as an indicator of whether or not a feature exists as it will return the same thing if -// the inputted feature is undefined or is defined without a vendor prefix. It takes the -// same parameters at BrowserHasFeature(). -function AppendPrefix(prefix, feature, isAttribute) -{ - if (prefix !== undefined) - { - if (isAttribute) - { - // if a certain feature is an attribute, then it follows a different naming standard - // where it must be completely capitalized and have words split with an underscore - return prefix.toUpperCase() + "_" + feature.toUpperCase(); - } - else - { - //Vendor prefixing should follow the standard convention: vendorprefixFeature - //Note that the feature is capitalized after the vendor prefix - //Therefore if the feature is window.feature, the vendor prefix version is: - //window.[vp]Feature where vp is the vendor prefix: - //window.msFeature, window.webkitFeature, window.mozFeature, window.oFeature - var newFeature = feature[0].toUpperCase() + feature.substr(1, feature.length); - - //Build up the new feature name with the vendor prefix - return prefix + newFeature; - } - } - else - { - return feature; - } -} \ No newline at end of file diff --git a/vibration/support/helpers.js b/vibration/support/helpers.js deleted file mode 100644 index cf16f76..0000000 --- a/vibration/support/helpers.js +++ /dev/null
@@ -1,13 +0,0 @@ - -function supportsVibration () { - if (undefined !== BrowserHasFeature(navigator, "vibrate")) { - return true; - } - else { - test(function () { - assert_true(false, "Vibration API not found"); - }, "Your user agent does not support the Vibration API."); - return false; - } -} -